<template>
	<view>
		<uni-list>
			<uni-list :border="true">
				<!-- 右侧带角标 -->
				<uni-list-chat :avatar-circle="true" title="交易通知"
					avatar="../../static/chat.png" note="您收到一条新的消息"
					time="2020-02-02 20:20" badge-text="2"></uni-list-chat>
				<uni-list-chat :avatar-circle="true" title="订单助手"
					avatar="../../static/chat1.png" note="您收到一条新的消息"
					time="2020-02-02 20:20" ></uni-list-chat>
			</uni-list>
		</uni-list>
		<uni-list>
			<uni-list :border="true">
				<view v-for="(item, index) in list" :key="index">
					<uni-list-chat :avatar-circle="true" :title="item.name"
						:to="`/pages/order/chat/chat?id=${item.orderId}`"
						avatar="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png" note="您收到一条新的消息"
						:time="item.createTime" badge-text="1" @click="chat()" link="navigateTo"></uni-list-chat>
				</view>
			</uni-list>
		</uni-list>
	</view>
</template>
<script>
	import {
		apiUrl
	} from '@/config/config.js';
	import counter from "@/components/counter/counter.vue"
	export default {
		components: {
			counter
		},
		data() {
			return {
				filt: '', // 记录当前的tab
				list: null, // 订单列表数据
				isLogin: false,
				apiUrl: apiUrl,
			}
		},

		methods: {
			checkLogin1() {
				try {
					const value = uni.getStorageSync('islogin_key');
					if (value) {
						this.isLogin = value;
					}
				} catch (e) {
					// error
				}

			},
			deleteOrder(id) {
				// console.log(`删除订单${id}`)
				uni.showModal({
					title: '友情提示',
					content: '您确定要删除该订单吗?',
					success: (res) => {
						if (res.confirm) {
							try {
								uni.request({
									url: this.apiUrl + `/api/order/${id}`,
									method: 'DELETE',
									success: (res) => {
										if (res.data.code == '200') {
											this.loadList();
										}
									}
								})
							} catch (e) {
								// error
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}

					}
				})

			},

			orderDetail(orderNumber) {
				console.log(`订单详情${orderNumber}`)
				uni.navigateTo({
					url: `/pages/order/order-details?orderNumber=${orderNumber}`
				});
			},

			orderUpdate(id) {
				console.log(`修改信息${id}`)
				uni.navigateTo({
					url: `/pages/order/edit?id=${id}`
				});
			},
			chat(id) {
				console.log("跳转")
				// uni.navigateTo({
				// 	url: `/pages/order/chat/chat?id=${id}`
				// });
			},
			orderjindu(id) {
				console.log(`订单进度${id}`)
				uni.navigateTo({
					url: `/pages/order/jindu?id=${id}`
				});
			},

			handleCounterOver() {
				// 倒计时结束时触发的逻辑
				console.log('倒计时结束');
				// 可以在这里进行一些操作，比如显示提示信息、更新订单状态等
			},
			// 订单状态筛选
			onFilterChange(e) {
				const curFilt = e.currentTarget.dataset.filt;
				if (curFilt === this.filt) return;
				this.filt = curFilt;
				this.loadList();
			},
			// 订单列表加载
			loadList() {
				uni.request({
					url: this.apiUrl + "/api/group/list",
					method: 'GET',
					data: {
						account: uni.getStorageSync('account_key')
					},
					success: res => {
						this.list = res.data.data;
					},
					fail: res => {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 1000
						});
					}
				});
			},
			// 跳转订单详情
			toOrder(id) {
				uni.navigateTo({
					url: `../order/order?oid=${id}`
				});
			},
		},
		onShow() {
			// 页面展示时调用订单列表
			this.loadList();
			this.checkLogin1();
		},
	}
</script>




<style>
	@import './index.css'
</style>